#ifndef CTRLSERVER_H
#define CTRLSERVER_H

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <regex.h>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#define OK				0
#define ERROR 			-1
#define FAILED			-1
#define WAIT			2
#define EN_DEBUG		1
#define PACKAGE_START	1
#define PACKAGE_UPDATE	2
#define SERVER_PORT 8888
#define UART_FD "/dev/ttySAC2"

const int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400,B19200, B9600, B4800, B2400, B1200, B300 };
int name_arr[] = { 38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200,9600, 4800, 2400, 1200, 300 };
const char *tmpFile = "./tmp.jpeg";
const float scale = 0.520;
char msg[256];
int fd = -1;
static struct sockaddr_in addr,sendaddr;

typedef struct led_parameter{
    int pack_type;
    int mode;
    int id;//更新包用
    int parameter;//更新包用（亮度x16+启用+红×2+绿x4+蓝x8）
}LedParameter;

int Uart_SendCmd(LedParameter lparam);
void Uart_SetSpeed(int fd, int speed);
static char* substr(const char*str,unsigned start, unsigned end);
int LED_Check(const char *str);
int LED_Decode(char *net_msg,LedParameter *lparam);
void onCamera(void);
bool stopCamera(void);
bool initServer(void);
int UDPLED_Server(void);

#endif // CTRLSERVER_H
